import {HttpHelper} from "./HttpHelper";
import {Injectable} from "@angular/core";
import {TransferEntry} from "./domains";


@Injectable()
export class TransferEntryService{
    transUrl = "transfers";
    constructor(private httpHelper:HttpHelper){

    }

    getTransfer(): Promise<TransferEntry[]> {
        let url = this.transUrl;
        return this.httpHelper.getJson<TransferEntry[]>(url);
    }

    addTransfer(receive:number,origin:number,target:number,transferEntry):Promise<TransferEntry> {
        let url = this.transUrl+`/?receive=${receive}&origin=${origin}&target=${target}`;
        return this.httpHelper.postToJson<TransferEntry>(url,transferEntry);
    }

    receiveTransfer(transfer:number):Promise<TransferEntry> {
        let url = this.transUrl+`/?transfer=${transfer}`;
        return this.httpHelper.putToJson<TransferEntry>(url,null);
    }

    billaddTransfer(bill):Promise<TransferEntry> {
        let url = this.transUrl+`/bills/?bill=${bill}`;
        return this.httpHelper.postToJson(url,null);
    }
}